#!/bin/bash
source include_bench.sh

do_bench() {
	# $1 libpath
	# $2 benchpath
	echo "LD_PRELOAD=$1 $2"
	${NICE} env LD_PRELOAD=$1 $2 2> ./log/tmp.tsv
	cat ./log/tmp.tsv
	cat ./log/tmp.tsv | while read line
	do
		echo "$3 ${line}" >> $4
	done
	# 确保文件已写入, 防止影响下一次执行
	sleep 1
}
# remove rcl
liblist="mutex
pspin
spin
ticket
clh
mcs
flat
ccsync
dsmsync
hsync
sffwd"

trap "exit" INT
echo "apfsds test run ${1} x 2 times (gcc + clang)"
mv ./log/apfsds_addresult.tsv ./log/apfsds_addresult_old.tsv

echo "lib bench threads result(mop/s)" > ./log/apfsds_addresult.tsv
for ((i=1;i<=${1};i++))
do
	for lib in ${liblist}   
	do
		do_bench ${curpath}/build_lib/glibapfsds_${lib}.so ${curpath}/build/gtest_apfsds_add.o ${lib} ./log/apfsds_addresult.tsv
		do_bench ${curpath}/build_lib/cllibapfsds_${lib}.so ${curpath}/build/cltest_apfsds_add.o ${lib} ./log/apfsds_addresult.tsv
	done
done
# cd script
# python3 geomean_apfsds.py ../log/apfsds_addresult.tsv